package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Quota;
import com.ruoyi.system.service.IQuotaService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 配额Controller
 * 
 * @author ruoyi
 * @date 2025-02-08
 */
@RestController
@RequestMapping("/system/quota")
public class QuotaController extends BaseController
{
    @Autowired
    private IQuotaService quotaService;

    /**
     * 查询配额列表
     */
    @PreAuthorize("@ss.hasPermi('system:quota:list')")
    @GetMapping("/list")
    public TableDataInfo list(Quota quota)
    {
        startPage();
        List<Quota> list = quotaService.selectQuotaList(quota);
        return getDataTable(list);
    }

    /**
     * 导出配额列表
     */
    @PreAuthorize("@ss.hasPermi('system:quota:export')")
    @Log(title = "配额", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Quota quota)
    {
        List<Quota> list = quotaService.selectQuotaList(quota);
        ExcelUtil<Quota> util = new ExcelUtil<Quota>(Quota.class);
        util.exportExcel(response, list, "配额数据");
    }

    /**
     * 获取配额详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:quota:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(quotaService.selectQuotaById(id));
    }

    /**
     * 新增配额
     */
    @PreAuthorize("@ss.hasPermi('system:quota:add')")
    @Log(title = "配额", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Quota quota)
    {
        return toAjax(quotaService.insertQuota(quota));
    }

    /**
     * 修改配额
     */
    @PreAuthorize("@ss.hasPermi('system:quota:edit')")
    @Log(title = "配额", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Quota quota)
    {
        return toAjax(quotaService.updateQuota(quota));
    }

    /**
     * 删除配额
     */
    @PreAuthorize("@ss.hasPermi('system:quota:remove')")
    @Log(title = "配额", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(quotaService.deleteQuotaByIds(ids));
    }
}
